package com.example.hotelmanagement.controller;

import com.example.hotelmanagement.entity.Result;
import com.example.hotelmanagement.entity.Room;
import com.example.hotelmanagement.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/rooms")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @GetMapping
    public Result getAllRooms() {
        return Result.ok(roomService.findAll());
    }

    @GetMapping("/{id}")
    public Result getRoomById(@PathVariable Integer id) {
        Room room = roomService.findById(id);
        return room != null ? Result.ok(room) : Result.error();
    }

    @GetMapping("/status/{status}")
    public Result getRoomsByStatus(@PathVariable String status) {
        return Result.ok(roomService.findByStatus(status));
    }

    @PostMapping
    public Result createRoom(@RequestBody Room room) {
        return Result.ok(roomService.save(room));
    }

    @PutMapping
    public Result updateRoom(@RequestBody Room room) {
        return Result.ok(roomService.update(room));
    }

    @DeleteMapping("/{id}")
    public Result deleteRoom(@PathVariable Integer id) {
        return Result.ok(roomService.delete(id));
    }
}